﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Web.Mvc;
using Sharp.DataTransferObject;
using Sharp.Infrastructure;
using Sharp.Infrastructure.WebApiClient;
using Sharp.Portal.AdminLTE;
using Sharp.Portal.Mvc;
using Sharp.ServiceContracts;
using Sharp.WebBooter.Areas.Demo.Models;

using UserIndexViewModel = Sharp.WebBooter.Areas.Demo.Models.UserIndexViewModel;

namespace Sharp.WebBooter.Areas.Demo.Controllers
{
    [Authorize]
    [AutomaticTemplate]
    public class TabController : SharpController
    {
        public ActionResult Index()
        {
            return View(new UserIndexViewModel());
        }

        /// <summary>
        ///     分页数据
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public ActionResult GetPaged(DataTableParameter parameters)
        {
            using (var proxy = new WebApiClientServiceProxy<IUserService>())
            {
                var pageInfo = proxy.Channel.GetUsersPaged(parameters.ToPagingFeature());

                return this.Store(pageInfo);
            }
        }

        public ActionResult Details(int? id)
        {
            UserDTO userDto;
            using (var proxy = new WebApiClientServiceProxy<IUserService>())
            {
                userDto = proxy.Channel.GetUserByKey(id.Value).Data;
            }
 
            var vm = userDto.To<UserViewModel>();
            userDto.Password = string.Empty;


            return View(vm);
        }

        public ActionResult Create()
        {
            var vm = new UserViewModel();


            return View(vm);
        }
    }
}